package com.shoulei.designpattern.prototypePattern;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName:ShapeCache
 * @Descrition:
 * @Author:shoulei
 * @Date:2019/3/31 21:07
 * @Verson:
 */
public class ShapeCache {
    public static Map<String, Shape> shapeMap = new HashMap<String, Shape>();

    public Shape getShape(String shapeId){
        Shape cacheShape = shapeMap.get(shapeId);
        return (Shape) cacheShape.clone();
    }

    public static void loadCache(){
        Circle circle = new Circle();
        circle.setId("1");
        shapeMap.put(circle.getId(),circle);

        Rectangle rectangle = new Rectangle();
        rectangle.setId("2");
        shapeMap.put(rectangle.getId(),rectangle);

    }

}
